﻿using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;

namespace Batman.BLL.UserModule.Extensions
{
    public static class PrincipalExtensions
    {
        public static int GetUserId(this ClaimsPrincipal principal)
        {
            var claims = principal.Identities.SelectMany(t => t.Claims);
            var item = claims.FirstOrDefault(s => s.Type == ClaimTypes.NameIdentifier);
            if (item == null) return 0;

            int.TryParse(item.Value, out int result);
            return result;
        }
    }
}
